package com.company.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.base.common.persistence.Page;
import com.base.common.service.CrudService;
import com.base.common.utils.SQLUtil;
import com.company.dao.CompanyEmployeeMapper;
import com.company.model.CompanyEmployee;
import com.company.service.EmployeeService;

@Service
public class EmployeeServiceImpl extends
		CrudService<CompanyEmployeeMapper, CompanyEmployee> implements
		EmployeeService {

	public Page findEmployeeByCompanyId(String companyId, Page page) throws Exception{

		Map<String, String> params = new HashMap<String, String>();
		params.put("companyId", companyId);
		String sql = "SELECT * from company_employee t where t.company_Id = #{companyId} ";
		page = this.getPage(page, sql, CompanyEmployee.class, params);
		return page;
	}

	public boolean deleteEmployeeByIds(String ids) throws Exception {
		String sql = "delete from company_Employee where id in ("
				+ SQLUtil.createInStr(ids) + ") ";
		int res = this.delete(sql);
		return true;
	}

	public boolean saveEmployee(CompanyEmployee companyEmployee)
			throws Exception {
		int res = this.saveOrUpdate(companyEmployee);
		return true;
	}

	public List<CompanyEmployee> findEmployeeListByCompanyId(String companyId)
			throws Exception {
		Map<String, String> params = new HashMap<String, String>();
		params.put("companyId", companyId);
		String sql = "SELECT * from company_employee t where t.company_Id = #{companyId} ";
		List<CompanyEmployee> list = this.getList(sql, CompanyEmployee.class,
				params);
		return list;
	}
	
	public CompanyEmployee findEmployeeById(String id)
			throws Exception {
		return this.get(id);
	}
}
